package com.xhcl.web.controller.system;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xhcl.common.annotation.Log;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.system.domain.AccountReport;
import com.xhcl.system.domain.TGgHsdw;
import com.xhcl.system.domain.TGgKmdm;
import com.xhcl.system.domain.TSrhsAccountTemp;
import com.xhcl.system.domain.TSrhsHsxtcs;
import com.xhcl.system.domain.TSrhsKmye;
import com.xhcl.system.domain.TSrhsZybb;
import com.xhcl.system.service.ITGgHsdwService;
import com.xhcl.system.service.ITSrhsAccountTempService;
import com.xhcl.system.service.ITSrhsHsxtcsService;
import com.xhcl.system.service.ITSrhsKmyeService;
import com.xhcl.system.service.ITSrhsZybbService;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.common.utils.StringUtils;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.framework.shiro.util.ShiroUtils;
import com.xhcl.common.core.page.TableDataInfo;

/**
 * 专项基金Controller
 * 
 * @author xhcl
 * @date 2020-09-03
 */
@Controller
@RequestMapping("/system/zxjj")
public class TSrhsZxjjController extends BaseController
{
    private String prefix = "system/zxjj";

    @Autowired
    private ITSrhsAccountTempService tSrhsAccountTempService;
    @Autowired
    private ITSrhsHsxtcsService tSrhsHsxtcsService;
    
    @Autowired
    private ITGgHsdwService tGgHsdwService;
    
    @Autowired
    private ITSrhsZybbService tSrhsZybbService;

    @RequiresPermissions("system:zxjj:view")
    @GetMapping()
    public String zxjj(ModelMap mmap)
    {
    	String year=tSrhsHsxtcsService.getHsxtcsnr("year");
    	String term=tSrhsHsxtcsService.getHsxtcsnr("term");
    	List<String> ndlist=new ArrayList();
    	for (int i=0;i<5;i++) {
    		ndlist.add(String.valueOf(Integer.parseInt(year)-i));
    	}
    	mmap.put("ndlist", ndlist);
    	mmap.put("year", year);
    	List<String> yflist=new ArrayList();
    	for (int i=1;i<=12;i++) {
    		yflist.add(String.valueOf(i));
    	}
    	mmap.put("yflist", yflist);
    	mmap.put("term", term);
    	List<TSrhsZybb> zxjjlist=tSrhsZybbService.selectTSrhsZybbList(null);
    	mmap.put("zxjjlist", zxjjlist);
        return prefix + "/zxjj";
    }
    


    /**
     * 查询专项基金列表
     */
    @RequiresPermissions("system:zxjj:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TSrhsKmye srhsKmye)
    {
    	
    	Map<String,Object> map=new HashMap<String,Object>();
    	String kmdm=tSrhsHsxtcsService.getHsxtcsnr("zxjj");
    	if (StringUtils.isEmpty(kmdm)){
    		kmdm="502";
    	}
    	map.put("nd", srhsKmye.getNd());
    	map.put("yf", srhsKmye.getYf());
    	map.put("kmdm", kmdm);
    	List<TSrhsAccountTemp> list = tSrhsAccountTempService.callZxjjReport(map);
        return getDataTable(list);
    }

    /**
     * 导出专项基金
     */
    @RequiresPermissions("system:zxjj:export")
    @Log(title = "专项基金", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSrhsKmye srhsKmye)
    {
    	Map<String,Object> map=new HashMap<String,Object>();
    	map.put("nd", srhsKmye.getNd());
    	map.put("yf", srhsKmye.getYf());
    	map.put("kmdm", "");
    	List<TSrhsAccountTemp> list = tSrhsAccountTempService.callZxjjReport(map);
        ExcelUtil<TSrhsAccountTemp> util = new ExcelUtil<TSrhsAccountTemp>(TSrhsAccountTemp.class);
        return util.exportExcel(list, "zxjj");
    }

    
     
}
